import Vue from "vue";
import Router from "vue-router";
/* Layout */
import Layout from "@/layout";
/* Router Modules */
// import tableRouter from "./modules/table";

Vue.use(Router);

export const constantRoutes = [
	{
		path: "/redirect",
		component: Layout,
		children: [
			{
				path: "/redirect/:path(.*)",
				component: () => import("@/views/redirect/index")
			}
		]
	},
	{
		path: "/login",
		component: () => import("@/views/login/index")
	},
	{
		path: "/",
		component: Layout,
		redirect: "/home",
		affixbar: true,
		children: [
			{
				path: "home",
				component: () => import("@/views/home/index"),
				name: "Home",
				meta: { name: "首页", icon: "home-o", affixbar: true }
			}
		]
	},
	{
		path: "/billing",
		component: Layout,
		affixbar: true,
		children: [
			{
				path: "/",
				component: () => import("@/views/billing/index"),
				name: "Billing",
				meta: { name: "开票", icon: "newspaper-o", affixbar: true, dot: true }
			}
		]
	},
	{
		path: "/wallet",
		component: Layout,
		affixbar: true,
		children: [
			{
				path: "/",
				component: () => import("@/views/wallet/index"),
				name: "Wallet",
				meta: { name: "票夹", icon: "cash-on-deliver", affixbar: true, badge: 5 }
			}
		]
	},
	{
		path: "/mine",
		component: Layout,
		affixbar: true,
		children: [
			{
				path: "/",
				component: () => import("@/views/mine/index"),
				name: "Mine",
				meta: { name: "我的", icon: "user-o", affixbar: true, badge: 10 }
			}
		]
	}
	/* {
		path: "/example",
		component: Layout,
		children: [
			{
				path: "/",
				component: () => import("@/views/example/index"),
				name: "Example",
				meta: { name: "示例" }
			}
		]
	} */
];

/**
 * asyncRoutes
 * the routes that need to be dynamically loaded based on user roles
 */
export const asyncRoutes = [
	{
		path: "/example",
		component: Layout,
		children: [
			{
				path: "/",
				component: () => import("@/views/example/index"),
				name: "Example",
				meta: { name: "示例" }
			}
		]
	}
	/* {
		path: "/tab",
		component: Layout,
		children: [
			{
				path: "index",
				component: () => import("@/views/tab/index"),
				name: "Tab",
				meta: { title: "Tab", icon: "tab" }
			}
		]
	},

	tableRouter */
];

const createRouter = () =>
	new Router({
		// mode: 'history', // require service support
		scrollBehavior: () => ({ y: 0 }),
		routes: constantRoutes
	});

const router = createRouter();

export function resetRouter() {
	const newRouter = createRouter();
	router.matcher = newRouter.matcher; // reset router
}

export default router;
